package com.ugoodtech.mdcc.core.repository;

/* Copyright (C) Ugoodtech, Inc - All Rights Reserved.
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 * Proprietary and confidential.
 * Written by Stone Shaw.
 */

import com.ugoodtech.mdcc.core.domain.Nation;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface NationRepository extends CrudRepository<Nation, Long>, QueryDslPredicateExecutor<Nation> {
//    Nation findByCodeAndCity(String code,String city);

    List<Nation> findByParent(Nation nation);

    List<Nation> findByCode(String code);

    @Query("from Nation where code=:code")
    Nation findOneByCode(@Param("code") String code);

    @Query("from Nation where district=:district")
    Nation findByDistrict(@Param("district") String district);

    @Query("from Nation where province=:province")
    Nation selectByProvince(@Param("province") String province);

    @Query("from Nation where city=:city")
    List<Nation> selectByCity(@Param("city") String city);

    @Query(value = "select * from nation where province!='' ", nativeQuery = true)
    List<Nation> findProvince();

}
